package com.weaver.drools.business.drools.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.weaver.drools.business.drools.service.IActRuleService;
import com.weaver.drools.business.drools.service.IPersonService;
import com.weaver.drools.common.drools.executor.RuleExecutor;
import com.weaver.drools.common.drools.service.ReloadDroolsRuleService;
import com.weaver.drools.common.entity.Person;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

@Controller
public class TestController {

    @Resource
    private ReloadDroolsRuleService reloadDroolsRuleService;
    @Resource
    private IPersonService personService;
    @Resource
    private IActRuleService actRuleService;
    
	@ResponseBody
    @RequestMapping(value = "/queryList",method = RequestMethod.GET)
    public void test(){
		Person p= new Person();
        Map<String,Object> mapList = new HashMap<>();
        mapList.put("personService", personService);
        mapList.put("actRuleService", actRuleService);
        RuleExecutor.execute("inpection_check",p,mapList);
    }

    @ResponseBody
    @RequestMapping("/reloadRule")
    public String reload() throws IOException {
    	reloadDroolsRuleService.reloadRule();
        return "ok";
    }
    @ResponseBody
    @RequestMapping("/reloadRuleByFileName")
    public String reloadRuleByFileName() throws IOException {
    	String fileName="inpection_check.drl";
    	reloadDroolsRuleService.reloadRule(fileName);
        return "ok";
    }
}
